$(document).ready(function() {
	var mapSize = "small";

	// Map resizing
	$("#enlargeToggle").click(function() {
		if(mapSize == "small") {
			$("#map")
				.animate({
					"width":  "1030px",
					"height": "650px"
				}, "fast");
			mapSize = "large";
		}
		else {
			$("#map")
				.animate({
					"width":  "515px",
					"height": "325px"
				}, "fast");
			mapSize = "small";
		}
	});

	// Spring
	$("#addMarker").click(function() {
		var bounds = map.getBounds();
		var southWest = bounds.getSouthWest();
		var northEast = bounds.getNorthEast();
		var lngSpan = northEast.lng() - southWest.lng();
		var latSpan = northEast.lat() - southWest.lat();
		var userLocation = new GLatLng(southWest.lat() + latSpan * Math.random(), southWest.lng() + lngSpan * Math.random());
		map.addOverlay(new GMarker(userLocation));
	});

	// Spring
	$("#setVisible").click(function() {
		$("#map")
			.animate({
				"opacity": "toggle"
		}, "normal");
	});

	// Spring
	$("#dimSwitch").click(function() {
		$(".spring")
			.animate({
				"opacity": "toggle"
		}, "normal");
	});

	// Drawer
	$("#map").mouseover(function() {
		if( ($("drawer").css("left") + $("#map").css("left")) != "545px") {
			$("drawer").animate({
				"left": "545px"
			}));
		}
	});

	/*
	q=6+Brightbay+Crescent,+Thornhill+ON
	output=json
	oe=utf8
	sensor=true
	key=ABQIAAAAY5CLrRrLBJN5eOAUMhOQahQFuii2RdR3ITLU0HZStEEQxFSHNRTi_d1KdPD9jm8UZexzIulYng7gEA
	ll=
	spn=
	gl=
	*/

	var requestNumber = JSONRequest.get(
		"http://maps.google.com/maps/geo?q=6+Brightbay+Crescent,+Thornhill+ON&output=json&oe=utf8&sensor=true&key=ABQIAAAAY5CLrRrLBJN5eOAUMhOQahQFuii2RdR3ITLU0HZStEEQxFSHNRTi_d1KdPD9jm8UZexzIulYng7gEA", 
		function (requestNumber, value, exception) {
			if (value) {
				processResponse(value);
			} else {
				processError(exception);
			}
		}
	);
});